子比主题美化 – 热门推荐排行榜页面

子比主题美化 – 热门推荐排行榜页面-小哥网
子比主题美化 – 热门推荐排行榜页面
此内容为付费资源,请付费后查看
1.88
限时特惠
9.9
付费资源
已售 77
图片[1]-子比主题美化 – 热门推荐排行榜页面-小哥网

核心代码

在主题的 func.php 中引入

//排行榜
function get_post_thumbnail_url($post_id) {
  $thumbnail_url = get_the_post_thumbnail_url($post_id, 'thumbnail');
  
  if (empty($thumbnail_url)) {
    $content = get_post_field('post_content', $post_id);
    
    if (strpos($content, '<img') !== false) {
      preg_match('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches);
      
      if (!empty($matches[1])) {
        $thumbnail_url = $matches[1];
        
        // 验证缩略图URL是否有效
        if (!filter_var($thumbnail_url, FILTER_VALIDATE_URL)) {
          $thumbnail_url = '';
        }
      }
    }
  }
  
  return $thumbnail_url;
}

引入区块

主题目录下的 index.php 中引入以下代码,放置于 <?php get_footer(); 前

<?php
if (file_exists(get_theme_file_path('/Index_rankinglist.php'))) {
    require_once get_theme_file_path('/Index_rankinglist.php');
}
?>

引入JS

<script type='text/javascript' src='https://huliku.com/huliku/js/ranking.js'></script>

上传文件放置于主题目录下即可

© 版权声明
THE END
喜欢就支持一下吧
点赞91 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容